package com.ourway.dtos;

import cn.hutool.core.annotation.Alias;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.ourway.entity.FeiShuDepartmentSync;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.Assert;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 飞书创建用户DTO
 *
 * @author liuweiheng
 * @since 2021/12/12
 */
@Data
@Accessors(chain = true)
@Builder
public class FeiShuUserAddDTO implements Serializable {
    /**
     * 名称
     */
    @JsonProperty("name")
    private String name;
    /**
     * 手机号
     */
    @JsonProperty("mobile")
    private String mobile;
    /**
     * 部门ID列表
     */
    @JsonProperty("department_ids")
    @Alias("department_ids")
    private String[] departmentIds;
    /**
     * 领导ID
     */
    @JsonProperty("leader_user_id")
    @Alias("leader_user_id")
    private String leaderUserId;
    /**
     * 性别
     * 0：保密
     * 1：男
     * 2：女
     */
    @JsonProperty("gender")
    private Integer gender;
    /**
     * 邮箱
     */
    @JsonProperty("email")
    private String email;
    /**
     * 员工号
     */
    @JsonProperty("employee_no")
    @Alias("employee_no")
    private String employeeNo;
    /**
     * 员工类型
     */
    @JsonProperty("employee_type")
    @Alias("employee_type")
    private Integer employeeType;

    /**
     * UserDTO转换为FeiShuUserAddDTO
     * @param userDTO 用户信息
     * @return 飞书创建用户信息对象
     */
    public static FeiShuUserAddDTO userDto2FeiShuUserAddDto(UserDTO userDTO) {
        Assert.notNull(userDTO, "Illegal Param: userDTO");
        return FeiShuUserAddDTO.builder()
                .name(userDTO.getName())
                .mobile(userDTO.getMobile())
                .departmentIds(new String[] { userDTO.getDepartmentSyncId() })
                .leaderUserId(userDTO.getManagerSyncId())
                .gender(Integer.parseInt(userDTO.getGender()))
                .email(userDTO.getEmail())
                .employeeNo(userDTO.getUserNo())
                .employeeType(1)
                .build();
    }
}
